const { ccclass, property } = cc._decorator;

@ccclass
export default class PlayerControl extends cc.Component {

	@property(cc.Prefab)
	BulletPrefab: cc.Prefab = null



	start() {
		// move
		this.node.on(cc.Node.EventType.TOUCH_MOVE, (event) => {
			this.node.setPosition(event.getLocation())
		})
		// attack
		this.schedule(() => {
			// creat bullet
			let bullet = cc.instantiate(this.BulletPrefab)
			// set parent
			bullet.setParent(cc.director.getScene())
			// set bullet position
			bullet.x = this.node.x
			bullet.y = this.node.y + 60
		}, 0.3)
		// 开启碰撞检测
		cc.director.getCollisionManager().enabled = true
	}
	
	// 死亡
	die() {
		// 加载爆炸图片
		cc.loader.loadRes("hero1_die", cc.SpriteFrame, (err, res) => {
			this.node.getComponent(cc.Sprite).spriteFrame = res;
		})
		setTimeout(() => {
			this.node.destroy()
		}, 300)
	}
	update(dt) {

	}

}
